package com.gitee.swsk33.mapstructdemo.structmapper;

import com.gitee.swsk33.mapstructdemo.dataobject.FigureDO;
import com.gitee.swsk33.mapstructdemo.dataobject.StoryDO;
import com.gitee.swsk33.mapstructdemo.dto.FigureDTO;
import com.gitee.swsk33.mapstructdemo.dto.StoryDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper(uses = {SpecialWeaponMapper.class})
public interface StoryMapper {

	StoryMapper INSTANCE = Mappers.getMapper(StoryMapper.class);

	/**
	 * 定义故事DO转DTO
	 */
	StoryDTO toStoryDTO(StoryDO storyDO);

	/**
	 * 定义角色DO转DTO
	 * 忽略故事列表字段防止无限递归
	 */
	@Mapping(target = "stories", ignore = true)
	@Mapping(target = "guild", expression = "java(GuildMapper.INSTANCE.customDOToDTO(figureDO.getGuild()))")
	FigureDTO toFigureDTO(FigureDO figureDO);

	/**
	 * 定义角色DO列表转DTO列表
	 */
	List<FigureDTO> toFigureDTOList(List<FigureDO> figureDOList);

	/**
	 * 定义故事DO转DTO列表的方法
	 */
	List<StoryDTO> toStoryDTOList(List<StoryDO> storyDOList);

	/**
	 * 定义故事DTO转DO
	 */
	@Mapping(target = "figures", ignore = true)
	StoryDO toStoryDO(StoryDTO storyDTO);

	/**
	 * 定义故事DTO转DO列表的方法
	 */
	List<StoryDO> toStoryDOList(List<StoryDTO> storyDTOList);

}